package com.karina.visualization.chart.component;

import com.karina.visualization.chart.client.DisplayObject;

abstract public class UpdateableObject<T> implements DisplayObject<T> {

	protected boolean invalidateProperties = false;

	protected boolean invalidateModelProperties = false;

	private boolean invisible = false;

	public enum GradientType {
		LINER_GRAIDENT, RADIOUS_GRAIDENT;
	}

	protected void invaliadteChartObjectProperties() {
		invalidateProperties = true;
		getUpdateManager().registerComponent(this);
	}

	protected UpdateManager getUpdateManager() {
		UpdateableObject<?> parent = (UpdateableObject<?>) getParent();
		return parent.getUpdateManager();
	}

	protected void invalidteChartObjectModel() {
		invalidateModelProperties = true;
		getUpdateManager().registerComponent(this);
	}

	/**
	 * this method can be overreid, the method need to caculate the properties
	 * of Chart properties which is unrelated with Model's properties the
	 * properties could relate to the size/height/widget and someother
	 * properties which might cause the final update of whole chart.
	 * 
	 */
	abstract protected void caculateChartObjectProperties();

	/***
	 * This method can be overrided which reflect the data update of model
	 * content if the current model's update will cause the update of sub model
	 * the data should be caculated from here.
	 * 
	 */
	abstract protected void caculateChartObjectModelProperties();

	/**
	 * update UI component which will force the UI component to redraw again
	 * this method should be invoked when all update is ready and getting start
	 * to draw
	 * 
	 */
	void update() {
		caculateChartObjectModelProperties();
		caculateChartObjectProperties();
	}

	/**
	 * set the arpha of the class
	 * 
	 * @param arapha
	 */
	abstract protected void setArapha(double arpha);

	/***
	 * set current chart to be invisible this variable will stop the
	 * updateManager and chart widget update
	 * 
	 * 
	 * @param visible
	 */

	@Override
	public void setVsible(boolean visible) {
		if (visible == invisible)
			invaliadteChartObjectProperties();

		this.invisible = !visible;
	}

	@Override
	public boolean isInvisible() {

		return true;
	}

}
